def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def largest_prime_in_number(number):
    str_num = str(number)
    if len(str_num) != 4 or not str_num.isdigit():
        return 0
    
    for i in range(len(str_num), 0, -1):
        if is_prime(int(str_num[:i])):
            return int(str_num[:i])
    return 0


input_number = int(input("Введите четырехзначное число: "))
print(largest_prime_in_number(input_number))
